<template>
  <div class="btns" :style="{ paddingBottom: utils.windowBottom + 10 + 'px' }">
    <div
      @click.stop="saveOrDown"
      v-if="
        DocumentStatus == '' ||
        DocumentStatus == 'Z' ||
        DocumentStatus == 'A' ||
        DocumentStatus == 'D'
      "
    >
      {{ '保存' }}
    </div>
    <div
      class="pay"
      v-if="
        DocumentStatus == 'Z' || DocumentStatus == 'A' || DocumentStatus == 'D'
      "
      @click.stop="submitOrderFn"
    >
      提交
    </div>

  </div>   <div
      class="pay"
      v-if="DocumentStatus == 'B' || DocumentStatus == 'D'"
      @click.stop="auditOrderFn"
    >
      审核
    </div>
	<div
	  class="pay"
	  v-if="DocumentStatus == 'C' "
	  @click.stop="unAuditOrderFn"
	>
	  反审核
	</div>
</template>

<script setup lang="ts">
import { auditOrder, getOrderList, submitOrder, unAuditOrder } from '@/api/user';
import utils from '@/utils';
import { Utils } from '@/utils/utils';
import { ref, watch } from 'vue';
const props = defineProps({
  /**
   * 引用页面
   */
  title: {
    type: String,
    default: '',
  },
  /**
   * 状态
   */
  DocumentStatus: {
    type: String,
    default: '',
  },
  /**
   * 订单号
   */
  FBillNo: {
    type: String,
    default: '',
  },
});
const emit = defineEmits(['saveOrDown', 'submitOrder', 'auditOrder']);

/**
 * 点击保存
 */
const saveOrDown = () => {
  emit('saveOrDown');
};
/**
 * 提交订单
 */
const submitOrderFn = async () => {
  Utils.showModal('确定提交？', async () => {
    const res: any = await submitOrder({
      FormId: Utils.getFormId(props.title),
      data: JSON.stringify({
        Numbers: props.FBillNo,
      }),
    });
    console.log(res, '提交订单');
    if (res.Result.ResponseStatus.IsSuccess) {
      Utils.showErr('提交成功', () => {
        emit('submitOrder', true);
      });
      return true;
    } else {
      Utils.showErr(res.Result.ResponseStatus.Errors[0].Message, () => {
        emit('submitOrder', false);
      });

      return false;
    }
  });
};

/**
 * 审核单据
 */
const auditOrderFn = async () => {
  Utils.showModal('确定提交审核？', async () => {
    const res: any = await auditOrder({
      FormId: Utils.getFormId(props.title),
      data: JSON.stringify({
        Numbers: props.FBillNo,
      }),
    });
    console.log(res, '审核');
    if (res.Result.ResponseStatus.IsSuccess) {
      Utils.showErr('审核成功', () => {
        emit('auditOrder', true);
      });

      return true;
    } else {
      Utils.showErr(res.Result.ResponseStatus.Errors[0].Message, () => {
        emit('auditOrder', false);
      });
      return false;
    }
  });
};
/**
 * 反审核单据
 */
const unAuditOrderFn = async () => {
  Utils.showModal('确定反审核？', async () => {
    const res: any = await unAuditOrder({
      FormId: Utils.getFormId(props.title),
      data: JSON.stringify({
        Numbers: props.FBillNo,
      }),
    });
    console.log(res, '反审核');
    if (res.Result.ResponseStatus.IsSuccess) {
      Utils.showErr('反审核成功', () => {
        emit('auditOrder', true);
      });

      return true;
    } else {
      Utils.showErr(res.Result.ResponseStatus.Errors[0].Message, () => {
        emit('auditOrder', false);
      });
      return false;
    }
  });
};
</script>

<style lang="less" scoped>
.btns {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw;
  padding: 28rpx;
  display: flex;
  justify-content: flex-end;
  margin-top: 28rpx;
  z-index: 99;
  background-color: #fff;
  view {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 30rpx;
    margin-right: 20rpx;
    border-radius: 24rpx;
    font-size: 30rpx;
    background-color: #3974f6;
    color: #fff;
  }
  > view:last-child {
    margin-right: 0 !important;
  }
  .pay {
    border: 1px solid #3974f6;
    background-color: transparent;
    color: #3974f6;
  }
}
</style>
